//
//  MTRateNestViewController.swift
//  MT
//
//  Created by ooops on 2020/5/14.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import YPNavigationBarTransition
import MTCategory
import JXPagingView
import JXCategoryView
import DeviceKit
import JXSegmentedView


class MTRateNestViewController: BaseViewController {
    
    var naviDataSource = JXSegmentedTitleDataSource()
    lazy var naviSegmentedView = JXSegmentedView()
    lazy var listContainer = JXSegmentedListContainerView(dataSource: self, type: .scrollView)

    var lists: [JXSegmentedListContainerViewListDelegate] = [MTStrengthViewController(type: .charm), MTStrengthViewController(type: .strength)]
    
    private var discoverType: MTDiscoverTableFooterViewType = MTDiscoverTableFooterViewType.charm
    
    convenience init(type: MTDiscoverTableFooterViewType) {
        self.init()
        self.discoverType = type
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let titles = ["魅力榜", "实力榜"]
        naviDataSource.titles = titles
        naviDataSource.itemSpacing = 36
        naviDataSource.itemContentWidth = 50
        naviDataSource.titleNormalColor = UIColor.text.x9b9b9b
        naviDataSource.titleSelectedColor = UIColor.text.x1d1a1a
        naviDataSource.isTitleZoomEnabled = true
        naviDataSource.titleNormalFont = PingFangSCSemiboldFont(16)
        naviDataSource.titleSelectedFont = PingFangSCSemiboldFont(16)

        naviSegmentedView.contentEdgeInsetLeft = 15
        naviSegmentedView.contentEdgeInsetRight = 15
        naviSegmentedView.frame = CGRect(x: 0, y: 0, width: 180, height: 30)
        naviSegmentedView.dataSource = naviDataSource
        naviSegmentedView.defaultSelectedIndex = discoverType == .strength ? 1 : 0
        
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorColor = UIColor.text.x1d1a1a
        indicator.indicatorWidth = 20
        indicator.indicatorHeight = 3
        naviSegmentedView.indicators = [indicator]

        navigationItem.titleView = naviSegmentedView

        view.addSubview(listContainer)

        naviSegmentedView.listContainer = listContainer
        //listContainer.scrollView.isScrollEnabled = false
        
        //扣边返回处理，下面的代码要加上
        naviSegmentedView.listContainer?.contentScrollView().panGestureRecognizer.require(toFail: self.navigationController!.interactivePopGestureRecognizer!)
        
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        listContainer.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
}

extension MTRateNestViewController: JXSegmentedListContainerViewDataSource {
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        return 2
    }

    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        return lists[index]
    }
}

extension MTRateNestViewController {
    override func yp_navigtionBarConfiguration() -> YPNavigationBarConfigurations {
        return [.backgroundStyleColor, .backgroundStyleOpaque, .showShadowImage]
    }
}
